﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace SocketServer
{
    public partial class frmSetting : Form
    {
        public frmSetting()
        {
            InitializeComponent();
        }

        private void frmSetting_Load(object sender, EventArgs e)
        {
            IniFile iFile = new IniFile(Application.StartupPath + "\\BrsService.ini");
            try
            {
                Port.Text = iFile.ReadInt("Setting", "Port", 6600).ToString();
            }
            catch (Exception)
            {
                Port.Text = "6600";
            }

            txtDataBase.Text = iFile.ReadString("Setting", "DataBase", "");
            txtUserID.Text = iFile.ReadString("Setting", "uid","");
            txtPwd.Text = iFile.ReadString("Setting", "pwd", "");
            txtServer.Text = iFile.ReadString("Setting", "server", "");
        }

        private void CmdSave_Click(object sender, EventArgs e)
        {
            if (Port.Text == "")
            {
                MessageBox.Show("服务器端口不能为空,请录入");
                return;
            }
            if (txtServer.Text == "")
            {
                MessageBox.Show("数据库服务地址不能为空,请录入");
                return;
            }
            if (txtDataBase.Text == "")
            {
                MessageBox.Show("数据库名称不能为空,请录入");
                return;
            }
            if (txtUserID.Text == "")
            {
                MessageBox.Show("用户名称不能为空,请录入");
                return;
            }
            if (txtPwd.Text == "")
            {
                MessageBox.Show("用户密码不能为空,请录入");
                return;
            }
            IniFile iFile = new IniFile(Application.StartupPath + "\\BrsService.ini");
            iFile.WriteString("Setting", "Port", Port.Text);
            iFile.WriteString("Setting", "DataBase", txtDataBase.Text);
            iFile.WriteString("Setting", "uid", txtUserID.Text);
            iFile.WriteString("Setting", "pwd", txtPwd.Text);
            iFile.WriteString("Setting", "server", txtServer.Text);
            MessageBox.Show("保存成功");
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }




    }
}
